package com.cskaoyan.controller.admin.promotion;

import com.cskaoyan.bean.MarketCoupon;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.vo.admin.promotion.AdminAdDeleteVO;
import com.cskaoyan.service.admin.promotion.AdminCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/*
 * @Auther:王贲
 * @Date:2022/9/7
 * @Description:
 * @VERSON:1.8
 */
@RestController
@RequestMapping("admin/coupon")
public class AdminCouponController {

    @Autowired
    AdminCouponService adminCouponService;


    /**
     * @return com.cskaoyan.bean.common.BaseRespVo
     * @description : TODO 显示优惠劵页面并且按需求查找优惠券
     * @author wang'ben
     * @date 2022/9/7 20:14
     */
    @RequestMapping("list")
    public BaseRespVo listCoupon(BasePageInfo basePageInfo, String name, Integer type, Integer status) {
        CommonData commonData = adminCouponService.selectCouponInfo(basePageInfo, name, type, status);
        return BaseRespVo.ok(commonData);
    }


    /**
     * @return com.cskaoyan.bean.common.BaseRespVo
     * @description : TODO 添加优惠券
     * @author wang'ben
     * @date 2022/9/8 18:09
     */
    @PostMapping("create")
    public BaseRespVo createCoupon(@RequestBody MarketCoupon marketCoupon) {
        adminCouponService.insertCouponInfo(marketCoupon);
        return BaseRespVo.ok(marketCoupon);
    }


    /**
     * @return com.cskaoyan.bean.common.BaseRespVo
     * @description : TODO 进入优惠券详情页面
     * @author wang'ben
     * @date 2022/9/8 18:11
     */
    @GetMapping("listuser")
    public BaseRespVo listuserCoupon(BasePageInfo basePageInfo, Integer couponId) {
        CommonData commonData = adminCouponService.selectListuserInfo(basePageInfo, couponId);
        return BaseRespVo.ok(commonData);
    }


    /**
     * @return com.cskaoyan.bean.common.BaseRespVo
     * @description : TODO 进入优惠券详情页面
     * @author wang'ben
     * @date 2022/9/8 19:06
     */
    @GetMapping("read")
    public BaseRespVo readCoupon(Integer id) {
        MarketCoupon marketCoupon = adminCouponService.selectCouponInfoById(id);
        return BaseRespVo.ok(marketCoupon);
    }


    /**
     * @return com.cskaoyan.bean.vo.admin.promotion.AdminAdDeleteVO
     * @description : TODO 删除优惠券
     * @author wang'ben
     * @date 2022/9/8 19:08
     */
    @PostMapping("delete")
    public AdminAdDeleteVO deleteCoupon(@RequestBody MarketCoupon marketCoupon) {
        adminCouponService.deleteCouponInfo(marketCoupon);
        return AdminAdDeleteVO.ok("成功");
    }


    @PostMapping("update")
    public BaseRespVo updateCoupon(@RequestBody MarketCoupon marketCoupon) {
        adminCouponService.updateCouponStates(marketCoupon);
        return BaseRespVo.ok(marketCoupon);
    }
}
